if (typeof(JapWord) == "undefined") {
	JapWord = {};
}

JapWord.Page = new (function() {
	
	this.scrollX;
	this.scrollY;
	this.page;
	
	var $this = this;
	
	this.initUI = function(o) {
		var res = {};
		
		for (var i in o) {
			var svalue = o[i];
			var value;
			if (typeof(svalue) == "string") {
				value = $$(svalue);
				if (svalue[0] == "#" && svalue.indexOf(" ") == -1) {
					value = value[0];
				}
			} else if (typeof(svalue) == "object") {
				value = $this.initUI(svalue);
			}
			
			res[i] = value;
		};

		return res;
	};
	
	this.getPage = function() {
		var pathname = window.location.pathname;
		if (pathname == JapWord.Conf.INDEX) {
			pathname += "index.html";
		}
		return pathname;
	}
	
	this.isIndexPage = function(page) {
		var pageIndex2 = JapWord.Conf.INDEX+"index.html";
		if (page == JapWord.Conf.INDEX || page == pageIndex2) {
			return true;
		}
		return false;
	};
	
	this.getHash = function() {
		return window.location.hash;
	}
	
	this.saveCurrentPage = function() {
		var objpage = {
			scrollX: window.scrollX,
			scrollY: window.scrollY,
			page: $this.getPage()
		}
		
		localStorage.setItem("CurrentPage", JSON.stringify(objpage));
	};
	
	this.loadSavedPage = function() {
		var objpage = JSON.parse(localStorage.getItem("CurrentPage"));
		for (var i in objpage) {
			if (typeof(objpage[i]) != "function") {
				$this[i] = objpage[i];
			}
		}
	};
});